﻿using LBSoft.Common.DotNetCode;
using LBSoft.Common.DotNetEncrypt;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace LBSoft.Business
{
    public class UserInfo_Dal
    {
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userAccount"></param>
        /// <param name="userPwd"></param>
        /// <returns></returns>
        public DataTable UserLogin(string userAccount, string userPwd)
        {
            StringBuilder strSql = new StringBuilder($@"SELECT * FROM dbo.SYS_UserInfo WHERE UserAccount=@UserAccount AND UserPwd=@UserPwd AND IsDelete=0");
            SqlParam[] para = new SqlParam[]
            {
                new SqlParam("@UserAccount", userAccount),
                new SqlParam("@UserPwd", Md5Helper.MD5(userPwd, 32))
            };
            return DataFactory.SqlDataBase().GetDataTableBySQL(strSql, para);
        }

        /// <summary>
        /// 登录日志
        /// </summary>
        /// <param name="UserAccount"></param>
        /// <param name="loginAddress"></param>
        /// <param name="loginStatus"></param>
        /// <param name="platform"></param>
        public void SysLoginLog(string UserAccount, string loginAddress, string loginStatus, string platform)
        {
            Hashtable ht = new Hashtable();
            ht["GUID"] = CommonHelper.GetGuid;
            ht["UserAccount"] = UserAccount;
            ht["LoginIP"] = RequestHelper.GetIP();
            ht["LoginAddress"] = loginAddress;
            ht["LoginStatus"] = loginStatus;
            ht["LoginDate"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            ht["Platform"] = platform;
            DataFactory.SqlDataBase().InsertByHashtable("SYS_LoginLog", ht);
        }
    }
}
